function Calculate_Cart_Price(product_id)
{
	var qtyboxname='txt_quantity'+product_id;	
	var qty=document.getElementById(qtyboxname).value;	
	//var colorselname='sel_colors'+product_id;
	//var colors=document.getElementById(colorselname).selectedIndex.value;
	//var prodpricename='div_price'+product_id;
	//var price=document.getElementById(prodpricename).innerHTML;
	//var ship_pricename='div_shipcharge'+product_id;
	//var ship_charge=document.getElementById(ship_pricename).innerHTML;
	document.getElementById('current_prod_id').value=product_id;
	if(qty<=0)
	{
		alert("Invalid Quantity");
		return false;
	}
	
	var addon_price=document.getElementById('txt_addonPrice'+product_id).value;
	if(addon_price<=0)
	{
		var varify=confirm("No addon selected. Are you sure to proceed??");
		if(varify)
		{return true;}
		else 
		{return false;}		
	}
	else
	{
		var color=document.getElementById('txt_SelectedSize'+product_id).value;
		if(color=="")
		{
			alert("Select the appropriate size of addon by clicking it.");
			return false;
		}
		else 
		{return true;}
	}
	

	return true;
}

function AddCartValidate(product_id)
{
		
}

function BuyNowvalidate(product_id)
{
	
}


function viewcart()
{
	window.open("cart_view.php");
}

function selectSize(product_id, obj)
{
	document.getElementById('txt_SelectedSize'+product_id).value=obj.innerHTML;	
}

function selectColor(product_id, obj)
{
	var color=obj.innerHTML;
	color=color.substring(4);
	color=color.substring(0, color.indexOf('<'));
	document.getElementById('txt_SelectedColor'+product_id).value=color;
}

function selectedAddonPrice(product_id, obj)
{
	var m=obj.innerHTML; 
	m = m.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
	document.getElementById('txt_addonPrice'+product_id).value=m;				
}

function doShipChanges()
{
	document.getElementById('do_Changes').value="Y";
	alert('Latest changes will be saved with this checkout for further use.');
}

function validateCheckOut()
{
	var shipping_add=document.getElementsByName('shipping_add')[0].innerHTML;
	var bill_add=document.getElementsByName('bill_add')[0].innerHTML;
	var buyer_email=document.getElementsByName('buyer_email')[0].value;
	var buyer_paypal=document.getElementsByName('buyer_paypal')[0].value;
	var buyer_phone=document.getElementsByName('buyer_phone')[0].value;
	
	if(shipping_add=='' || bill_add=='' || buyer_email=='' || buyer_paypal=='' || buyer_phone=='')
	{
		alert('All Fields in Shipping Details are Mandatory.');
		return false;
	}
	
	if( !(emailvalidate(buyer_email)))
	{
		return false;
	}
	
	return true;	
}

	function emailvalidate(str) 
	{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}


function checkCartEmpty()
{
	
	var CartString=document.getElementById('cart_values').value;
	//alert(CartString);
	if(CartString.length<50)
	{ 
		alert('Cart Is Empty.');
		return false;
	}
	
	return true;
}

function checkBuyerLogin(Bid)
{
	if(Bid=="" || Bid==null)
	{
		alert("Buyers Need To Login To Re Order a Pervious Order.");
		return false;
	}
	return true;
}